//引入获取商品的请求方法
import * as api from "@/api"
export default {
  namespaced: true,
  state: {
    productData: []
  },
  mutations: {
    //更改productDatade的mutation
    SET_PRODUCT_DATA(state, paylord) {
      state.productData = paylord
    },
    //减少库存
    DECREASE_INVENTORY(state, paylord) {
      let target = state.productData.find((item) => item.id === paylord)
      if (target) {
        target.inventory--
      }
    }
  },
  actions: {
    async FETCH_PRODUCT(context) {
      let res = await api.fetchProduct()
      console.log(res)
      context.commit("SET_PRODUCT_DATA", res.data)
    }
  },
  getters: {}
}
